package cn.tedu.day01.jnsdlfaq.common.controller;

import cn.tedu.day01.jnsdlfaq.common.pojo.Login;
import cn.tedu.day01.jnsdlfaq.user.pojo.SysUser;
import cn.tedu.day01.jnsdlfaq.user.service.SysUserService;
import cn.tedu.day01.jnsdlfaq.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "*", maxAge = 3600)//跨域
public class LoginController {
    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("/login")//  http://localhost:8080/api/login
    public AjaxResult toLogin(@RequestBody Login login) {
        SysUser user = sysUserService.userLogin(login.getUsername(), login.getPassword());
        if (user != null) {
            return AjaxResult.success(user);
        }
        return AjaxResult.error(400, "请求失败");


    }

}
